package cn.player.act;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONObject;
import org.wysaid.nativePort.FilterProcessLibrary;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.player.R;
import cn.player.act.filter.CameraMainActivity;
import cn.player.act.vod.ColumnListActivity;
import cn.player.act.vod.VideoListActivity;
import cn.player.adapter.MainAdapter;
import cn.player.download.server.WebService;
import cn.player.media.entity.AdInfo;
import cn.player.media.entity.BaseUrl;
import cn.player.media.entity.VideoInfo;
import cn.player.media.util.ParseUtil;
import cn.player.tools.ScreenMonitor;
import cn.player.tools.ScreenMonitor.OnScreenListener;
import cn.player.utils.CommUtil;
import cn.player.view.PullDoorView;
import cn.player.view.PullDoorView.OnPullListener;
import cntv.player.core.util.LogUtil;
import cntv.player.core.util.SprefUtils;
import cntv.player.core.util.ToastUtil;
import cntv.player.core.util.Utils;
import cntv.player.engine.Const;

public class MainActivity extends BaseActivity implements OnItemClickListener {


    private String vodUrl = "http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=6295d93f4e964903bc5bd89ab8d35b5f";
    //		private String vodUrl = "http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=4f4cf4656be44a158e5541ea1deb88e9";
//		private String hlsUrl = "http://asp.cntv.lxdns.com/asp/hls/main/0303000a/3/default/4f4cf4656be44a158e5541ea1deb88e9/main.m3u8?maxbr=450";
//		private String hlsUrl = "http://edaoyou.qiniudn.com/uu/mp4/CowPose.mp4";
//    private String hlsUrl = "http://202.108.16.43:8005/live/flv/channel11";
//    private String hlsUrl = "http://videos.xingliaoapp.com/videos/146858045512172.m3u8";
    private String hlsUrl = "file:///storage/emulated/0/tempvideo/hsgjr_watermark2.mp4";

//		private String liveUrl = "http://vdn.apps.cntv.cn/api/getLiveUrlCommonApi.do?channel=pa://cctv_p2p_hdcctv13";

//		private String liveUrl="http://vdn.live.cntv.cn/api2/live.do?channel=pa://cctv_p2p_hdcctv5&client=androidapp";//cctv5
//		private String liveUrl="http://vdn.live.cntv.cn/api2/live.do?channel=pa://cctv_p2p_hdcctv13&client=androidapp";//cctv13
//		private String liveUrl="http://vdn.live.cntv.cn/api2/live.do?client=androidapp&channel=pa://cctv_p2p_hdcctv2&ip=8.8.8.8";//cctv2国外

    //vst抓取的直播地址，key值每次都不一样
    private String liveUrl = "http://scgd-m3u8.joyseetv.com:10009/m3u8?id=134350&version=1&rate=1000k&key=RWPWWWWcbgVVVVVV";

    private VideoInfo mVideoInfo;
    private ListView mLvPlayTest;
    private MainAdapter mMainAdapter;
    private List<Integer> mTitleInfos;
    private PullDoorView mPullDoorView;
    private ScreenMonitor mScreenMonitor;
    private OnScreenListener mScreenStateListener;
    private TextView mTvHint;
    private AlphaAnimation animHint;

//    private FilterProcessLibrary mProcessLibrary;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        CommUtil.disableKeyGuard(MainActivity.this);
        setContentView(R.layout.activity_main);


//        mProcessLibrary = new FilterProcessLibrary();

//        startWebService();
        initJsonData(Const.BASE_PATH);//获取相关主配置信息

        findViews();
        setListeners();
        getTitleInfos();

        mMainAdapter = new MainAdapter(this, mTitleInfos, R.layout.main_item_view);
        mLvPlayTest.setAdapter(mMainAdapter);

        //可将此监听置于BaseActivity中,监听应用所有的activity
        mScreenMonitor = new ScreenMonitor(mContext);
        mScreenMonitor.registerListener(mScreenStateListener);


        mPullDoorView.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        mPullDoorView.setVisibility(View.GONE);
                    }
                });
            }
        }, 1500);
    }

    private void getTitleInfos() {
        mTitleInfos = new ArrayList<>();
        mTitleInfos.add(R.string.play_vod1);
        mTitleInfos.add(R.string.play_vod2);
        mTitleInfos.add(R.string.play_vod3);
        mTitleInfos.add(R.string.play_p2p);
        mTitleInfos.add(R.string.play_p2p_h265);
        mTitleInfos.add(R.string.play_p2p_h265_2);
        mTitleInfos.add(R.string.play_live_sd);
        mTitleInfos.add(R.string.play_live_xinjiang);
        mTitleInfos.add(R.string.play_vitamio);
        mTitleInfos.add(R.string.get_device_info);
        mTitleInfos.add(R.string.download_test);
        mTitleInfos.add(R.string.afinal_get_code);
        mTitleInfos.add(R.string.live_channel_list);
        mTitleInfos.add(R.string.vod_channel_list);
        mTitleInfos.add(R.string.play_list_video);
        mTitleInfos.add(R.string.android_storage);
        mTitleInfos.add(R.string.leak_suspect_test);
        mTitleInfos.add(R.string.shake_test);
        mTitleInfos.add(R.string.gopush_test);
        mTitleInfos.add(R.string.snow_flake);
        mTitleInfos.add(R.string.socket_communicate_test);
        mTitleInfos.add(R.string.slide_menu_test);
        mTitleInfos.add(R.string.media_codec_filter_test);
        mTitleInfos.add(R.string.ffmpeg_transcode_test);
        mTitleInfos.add(R.string.ffmpeg_transcode_filter_test);
        mTitleInfos.add(R.string.data_binding_test);
        mTitleInfos.add(R.string.green_dao_test);
        mTitleInfos.add(R.string.diff_utils_test);
        mTitleInfos.add(R.string.rx_android_test);
    }


    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
//        stopWebService();
        mScreenMonitor.unregisterListener();
        CommUtil.ennableKeyGuard(MainActivity.this);
    }

    private void findViews() {

        mLvPlayTest = (ListView) findViewById(R.id.lv_play_test);
        mPullDoorView = (PullDoorView) findViewById(R.id.pull_door_view);
        mTvHint = (TextView) findViewById(R.id.tv_hint_text);

        animHint = new AlphaAnimation(0f, 1f);
        animHint.setDuration(1500);
        animHint.setRepeatMode(Animation.REVERSE);
        animHint.setRepeatCount(Animation.INFINITE);
        mTvHint.startAnimation(animHint);
    }

    private void setListeners() {

        mLvPlayTest.setOnItemClickListener(this);
        mScreenStateListener = new OnScreenListener() {

            @Override
            public void onUserPresent() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScreenOn() {
                // TODO Auto-generated method stub
            }

            @Override
            public void onScreenOff() {
                // TODO Auto-generated method stub
                mPullDoorView.showPullDoor();
            }
        };

        mPullDoorView.setOnPullListener(new OnPullListener() {

            @Override
            public void onPullStart() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPullEnd() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPullDoorDissmiss() {
                // TODO Auto-generated method stub
                if (animHint != null) {
                    animHint.cancel();
                }
            }

            @Override
            public void onPullDoorShow() {
                // TODO Auto-generated method stub
                if (animHint != null) {
                    animHint.start();
                }
            }
        });
    }

    private void startWebService() {
        Intent service = new Intent(mContext, WebService.class);
        startService(service);
    }

    private void stopWebService() {
        Intent service = new Intent(mContext, WebService.class);
        stopService(service);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
                            long id) {
        // TODO Auto-generated method stub
        switch (mTitleInfos.get(position)) {
            case R.string.play_vod1://点播(vid)可横屏可竖屏
                Intent systemPlayIntent = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                //点播基本信息
                mVideoInfo.setPort(true);
                mVideoInfo.setFlag(Const.VOD);
                mVideoInfo.setTitle("《原乡》 第1集");
//			mVideoInfo.setVid("cb5c152401444204b25a026f971c819f");//原乡第一集vid
                mVideoInfo.setVid("fdd25515dbb8410fa3887b1e2bba9e08");//测试点播1vid，极速码率240*180
//			mVideoInfo.setVid("c87ae068463042b6d62a37b6ced3af2a");//测试点播1vid，极速码率240*180
                //如果videoInfo传入了有效的vid,videoInfo.setDetailUrl(liveUrl)地址无效
//			videoInfo.setVid("ff6a3965d8dc497ab2be7e038ce94956");//蒙语视频测试
//			videoInfo.setVid("63cc8465e85a4e5ea25921b5a7f20b45");//获取此播放源的播放时长有问题
//			mVideoInfo.setVid("97368f959f8940df908b2a31f93dea91");//播放到一半就断了, failed to open segment, retry...

                //传入获取广告相关参数(如果不支持广告就不用传了)
            /*AdInfo adInfo = new AdInfo();
            adInfo.setCatalog("1");
			adInfo.setVideosetId("CN06");
			adInfo.setDuration("2718");
			adInfo.setVideoId("cb5c152401444204b25a026f971c819f");
			mVideoInfo.setAdInfo(adInfo);*/

                systemPlayIntent.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(systemPlayIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_vod2://标清点播(detailUrl)只横屏
                Intent liveIntentVod = new Intent(this, MediaPlay2Activity.class); //MediaPlay2Activity设置了android:screenOrientation="sensorLandscape"
                mVideoInfo = new VideoInfo();
                mVideoInfo.setFlag(Const.VODCACHE);
                mVideoInfo.setTitle("健身视频");
                mVideoInfo.setDetailUrl(hlsUrl);
//			mVideoInfo.setFlag(Const.VOD);main
//			mVideoInfo.setTitle("《原乡》 第1集");
//			mVideoInfo.setVid("5206dce638f34847ad01f56d43798fc6");//测试点播2vid，极速码率360*270

                liveIntentVod.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(liveIntentVod);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_vod3:
                Intent starIntent = new Intent(this, MediaPlayStarActivity.class);
                mVideoInfo = new VideoInfo();
                mVideoInfo.setFlag(Const.VODCACHE);
                mVideoInfo.setTitle("明星视频");
                mVideoInfo.setDetailUrl(hlsUrl);
                starIntent.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(starIntent);
                overridePendingTransition(R.anim.base_push_down_in, R.anim.base_push_stay);

                break;
            case R.string.play_p2p://p2p直播(pa://cctv_p2p_hdcctv13)
                Intent liveIntentCctv13 = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                //直播基本信息
                mVideoInfo.setRate(Const.PLAYER_MODE_TS);//P2P直播
                mVideoInfo.setTimeShift(false);
                mVideoInfo.setP2pProgress(true);
                mVideoInfo.setPort(true);
                mVideoInfo.setFlag(Const.LIVE);
                mVideoInfo.setTitle("CCTV13");
                mVideoInfo.setP2pUrl("pa://cctv_p2p_hdcctv13");

                //如果videoInfo传入了有效的p2pUrl,播放器获取vdnInfo进入直播，videoInfo.setDetailUrl(liveUrl)地址无效
//			videoInfo.setP2pUrl("pa://cctv_p2p_hdtsxjtv2");

                AdInfo liveAdInfo = new AdInfo();
                liveAdInfo.setAdMode(Const.AD_MODE_OVER);
                liveAdInfo.setAdProject(Const.AD_CNTV_TIYU);
                mVideoInfo.setAdInfo(liveAdInfo);

                liveIntentCctv13.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(liveIntentCctv13);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_p2p_h265://p2p直播(h265)
                Intent liveIntentH265 = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                //直播基本信息
                mVideoInfo.setRate(Const.PLAYER_MODE_TS);//P2P直播
                mVideoInfo.setTimeShift(false);
                mVideoInfo.setP2pProgress(true);
                mVideoInfo.setPort(true);
                mVideoInfo.setFlag(Const.LIVE);
                mVideoInfo.setTitle("h265test");
                mVideoInfo.setChannelId("h265");

                liveIntentH265.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(liveIntentH265);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_p2p_h265_2://p2p直播(h265_2)
                Intent liveIntentH2652 = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                //直播基本信息
                mVideoInfo.setRate(Const.PLAYER_MODE_TS);//P2P直播
                mVideoInfo.setTimeShift(false);
                mVideoInfo.setP2pProgress(true);
                mVideoInfo.setPort(true);
                mVideoInfo.setFlag(Const.LIVE);
                mVideoInfo.setTitle("h265_2test");
                mVideoInfo.setChannelId("h265_2");

                liveIntentH2652.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(liveIntentH2652);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_live_sd://标清直播(pa://cctv_p2p_hdcctv1)
                Intent liveIntentNormal = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                mVideoInfo.setPort(true);
                mVideoInfo.setTimeShift(true);
                mVideoInfo.setFlag(Const.LIVE);
                mVideoInfo.setRate(Const.PLAYER_MODE_SD);//Normal标清直播
                mVideoInfo.setTitle("CCTV1");
                mVideoInfo.setChannelId("cctv1");

                liveIntentNormal.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(liveIntentNormal);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_live_xinjiang://新疆台视频播放测试(p2p)
                Intent vitamioXj = new Intent(this, MediaPlayActivity.class);
                mVideoInfo = new VideoInfo();
                //点播基本信息
                mVideoInfo.setPort(true);
                mVideoInfo.setTitle("新疆台");
                mVideoInfo.setRate(Const.PLAYER_MODE_TS);//p2p极速直播

                mVideoInfo.setFlag(Const.LIVE);
                mVideoInfo.setP2pUrl("pa://cctv_p2p_hdtsxjtv14");
//			videoInfo.setP2pUrl("pa://cctv_p2p_hdcctv12");

                vitamioXj.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(vitamioXj);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_vitamio://Vitamio播放视频测试

                //TODO 修改IMediaPlayer.java中的 MEDIA_PLAYER_DEFAULT 变量为Vitamio播放
                Intent vitamioVodIntent = new Intent(this, MediaPlay3Activity.class);
                mVideoInfo = new VideoInfo();
                //点播基本信息
                mVideoInfo.setPort(true);

                mVideoInfo.setFlag(Const.VOD);
//			mVideoInfo.setTitle("《原乡》 第1集");
//			videoInfo.setVid("cb5c152401444204b25a026f971c819f");//原乡第一集vid

//			videoInfo.setVid("806bad4be65645e7baea062ced6fc303");//20141013新闻联播vid
//			videoInfo.setVid("97368f959f8940df908b2a31f93dea91");//播放到一半就断了, failed to open segment, retry...

                mVideoInfo.setTitle("新闻联播极速播放左侧有花屏问题...");
//			mVideoInfo.setVid("2485c0cf355f40e59b5f741eda2f621d");
                mVideoInfo.setVid("5206dce638f34847ad01f56d43798fc6");//测试点播2vid，极速码率360*270

//			mVideoInfo.setTitle("CCTV5");
//			mVideoInfo.setDetailUrl(liveUrl);

			/*videoInfo.setRate(Const.PLAYER_MODE_TS);
			videoInfo.setFlag(Const.LIVE);
			videoInfo.setChannelId("h265");*/
//			videoInfo.setChannelId("cctv4");

                vitamioVodIntent.putExtra(VideoInfo.class.getName(), mVideoInfo);
                startActivity(vitamioVodIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.get_device_info://获取设备信息
                showDeviceInfo();
                break;
            case R.string.leak_suspect_test:
                Intent leakTestIntent = new Intent(mContext, LeakSuspectActivity.class);
                startActivity(leakTestIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.download_test://下载功能测试
                Intent downloadTestIntent = new Intent(mContext, DownloadActivity.class);
                startActivity(downloadTestIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.afinal_get_code://Afinal网络访问代码提取测试
                netTest();
                break;
            case R.string.live_channel_list://直播频道列表
                Intent channelListIntent = new Intent(this, ChannelListActivity.class);
                startActivity(channelListIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.vod_channel_list://点播栏目列表
                Intent columnListIntent = new Intent(mContext, ColumnListActivity.class);
                startActivity(columnListIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.play_list_video://视频列表播放
                Intent videoListIntent = new Intent(mContext, VideoListActivity.class);
                startActivity(videoListIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.android_storage://Android存储访问及目录
                Intent storagePathIntent = new Intent(mContext, StoragePathActivity.class);
                startActivity(storagePathIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.shake_test://摇一摇功能测试
                Intent shakeTestIntent = new Intent(mContext, ShakeTestActivity.class);
                startActivity(shakeTestIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.gopush_test://gopush测试
                ToastUtil.showToast(this, "gopush测试,请稍候...", ToastUtil.LENGTH_SHORT);
			/*Intent goPushTestIntent = new Intent(mContext, GoPushTestActivity.class);
			startActivity(goPushTestIntent);
			overridePendingTransition(R.anim.base_push_right_in,R.anim.base_fade_out);*/
                break;
            case R.string.snow_flake://雪花飘呀飘
                Intent flakeViewIntent = new Intent(mContext, FlakeViewActivity.class);
                startActivity(flakeViewIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.socket_communicate_test://Socket通信测试
                Intent socketClientIntent = new Intent(mContext, SocketClientActivity.class);
                startActivity(socketClientIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.slide_menu_test:
                Intent slideMenuIntent = new Intent(mContext, MainSlidingMenuActivity.class);
                startActivity(slideMenuIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.media_codec_filter_test://MediaCodec 实现滤镜效果
                Intent cameraIntent = new Intent(mContext, CameraMainActivity.class);
                startActivity(cameraIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.ffmpeg_transcode_test://FFmpeg 转码
                final long startTimeTrans = System.currentTimeMillis();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        FilterProcessLibrary mProcessLibrary = new FilterProcessLibrary();
                        File inputFile = new File(getExternalCacheDir(), "rec_test_face.mp4");
                        File outputFile = new File(getExternalCacheDir(), "rec_test_face_transcodingOnly.mp4");
                        mProcessLibrary.transcodingOnly(inputFile.getPath(), outputFile.getPath());
                        Log.i("zl", "transcoding time: " + (System.currentTimeMillis() - startTimeTrans) / 1000 + "s");
                    }
                }).start();
                break;
            case R.string.ffmpeg_transcode_filter_test://FFmpeg 转码并添加滤镜
                final String filter_box_blur = "boxblur=2:1:cr=0:ar=0";//模糊处理
                final String filter_brightness = "eq=brightness=0.5";//高亮
                final String filter_edge_detect = "edgedetect=low=0.1:high=0.4";//边缘检测
                final String filter_color_balance = "colorbalance=rs=.3";//颜色平衡
                final String filter_gray = "colorchannelmixer=.3:.4:.3:0:.3:.4:.3:0:.3:.4:.3";//灰阶效果
                final String filter_brown = "colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131";//褐色效果
                final String filter_crop = "crop=w=100:h=100:x=50:y=50";//裁剪效果
                final String filter_drawbox = "drawbox=x=10:y=10:w=100:h=100:color=pink@0.5:t=max";
                final String filter_overlay = "movie=/storage/emulated/0/tempvideo/flower.png[wm];[in][wm]overlay=5:5[out]";
//                mFilterDesc = "movie=/storage/emulated/0/tempvideo/flower.png[logo];[in][logo]overlay=5:5[out]";

                final long startTime = System.currentTimeMillis();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        FilterProcessLibrary mProcessLibrary = new FilterProcessLibrary();
                        File inputFile = new File(getExternalCacheDir(), "rec_test_face.mp4");
                        File outputFile = new File(getExternalCacheDir(), "rec_test_face_transcoding_filter.mp4");
                        mProcessLibrary.transcoding(inputFile.getPath(), filter_color_balance, outputFile.getPath());
                        Log.i("zl", "transcoding time: " + (System.currentTimeMillis() - startTime) / 1000 + "s");
                    }
                }).start();
                break;


            case R.string.data_binding_test:
                Intent dataBindingIntent = new Intent(mContext, DataBindingTestActivity.class);
                startActivity(dataBindingIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.green_dao_test:
                Intent greenDaoIntent = new Intent(mContext, GreenDaoTestActivity.class);
                startActivity(greenDaoIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.diff_utils_test:
                Intent diffUtilsIntent = new Intent(mContext, DiffUtilsTestActivity.class);
                startActivity(diffUtilsIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            case R.string.rx_android_test:
                Intent rxAndroidIntent = new Intent(mContext, RxAndroidActivity.class);
                startActivity(rxAndroidIntent);
                overridePendingTransition(R.anim.base_push_right_in, R.anim.base_fade_out);
                break;
            default:
                break;
        }

    }

    public float screenDensity(Context context) {
        float density = context.getResources().getDisplayMetrics().density;
        return density;
    }

    private void showDeviceInfo() {
        // TODO Auto-generated method stub
        String deviceFeatures = "请查看showDeviceInfo()方法";
//		String deviceFeatures = Device.getDeviceFeatures(mContext);
        deviceFeatures = "width:" + Utils.screenWidth(mContext)
                + " px\nheight:" + Utils.screenHeight(mContext)
                + " px\ndensity:" + screenDensity(mContext);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Devices Message").setMessage(deviceFeatures)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
        builder.create().show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            this.finish();
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
//		Log.i("zl","MainActivity onResume");
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
//		Log.i("zl","MainActivity onPause");
    }

    private void netTest() {
        String url = "http://sl.8325.com/Services/UserServer.asmx/GetUserTerminals";
        AjaxParams params = new AjaxParams();
        params.put("LoginName", "35080000000005");
        finalHttp.post(url, params, new AjaxCallBack<String>() {

            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(String result) {
                LogUtil.i("zl", "result = " + result);
                dialogNetInfo("访问成功", result);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                LogUtil.i("zl", "errorNo = " + errorNo + ",strMsg = " + strMsg);
                dialogNetInfo("访问失败", "errorNo = " + errorNo + ",strMsg = " + strMsg);
            }
        });
    }

    private void dialogNetInfo(String title, String info) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title).setMessage(info)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
        builder.create().show();
    }

    @Override
    protected void initDataSuccess(String url, JSONObject response) {
        // TODO Auto-generated method stub
        super.initDataSuccess(url, response);
        try {
            if (url.equals(Const.BASE_PATH)) {
                if (response != null) {
                    SprefUtils.getInstance(mContext).putString(Const.SHAR_PREF_KEY_CONFIG, response.toString());

                    Map<Object, BaseUrl> baseUrls = ParseUtil.parseDataToMap(response, "data", "title", BaseUrl.class);
                    app.setBaseUrls(baseUrls);
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    protected void initDataFailed(String url, int errorNo, String strMsg) {
        // TODO Auto-generated method stub
        super.initDataFailed(url, errorNo, strMsg);
        Log.i("zl", "errorNo = " + errorNo + ",strMsg = " + strMsg);
        if (app.getBaseUrls() == null) {
            ToastUtil.showToast(mContext, "获取缓存主配置", ToastUtil.LENGTH_SHORT);
        } else {
            ToastUtil.showToast(mContext, "主配置获取失败，请重试...", ToastUtil.LENGTH_SHORT);
        }
    }


}
